home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Workspace / WrapperInspector / Source / ImageView.m < prev    next >
Text File  |  1995-06-12  |  3KB  |  88 lines

  1. //----------------------------------------------------------------------------------------------------
  2. //
  3. //    ImageView
  4. //
  5. //    Inherits From:        View
  6. //
  7. //    Declared In:        ImageView.h
  8. //
  9. //    Disclaimer
  10. //
  11. //        You may freely copy, distribute and reuse this software and its
  12. //        associated documentation. I disclaim any warranty of any kind, 
  13. //        expressed or implied, as to its fitness for any particular use.
  14. //
  15. //----------------------------------------------------------------------------------------------------
  16. #import "ImageView.h"
  17.  
  18.  
  19. @implementation ImageView
  20.  
  21. //----------------------------------------------------------------------------------------------------
  22. //  Private Methods
  23. //----------------------------------------------------------------------------------------------------
  24. - (NXPoint) _calculateCompositePoint
  25. {
  26.     //  Centers image in frame rect.  (No longer used as frame becomes
  27.     //  image size when image is set).
  28.     
  29.     NXSize    imageSize;
  30.     NXPoint    centerPoint = { 0.0, 0.0 };
  31.  
  32.     [image getSize: &imageSize];
  33.     
  34.     if  ( imageSize.width < NX_WIDTH(&frame)) 
  35.         centerPoint.x += (NX_WIDTH(&frame) - imageSize.width ) / 2.0;
  36.     
  37.     if  ( imageSize.height < NX_HEIGHT(&frame)) 
  38.         centerPoint.y += (NX_HEIGHT(&frame) - imageSize.height ) / 2.0;
  39.         
  40.     return centerPoint;
  41. }
  42.  
  43.  
  44. //----------------------------------------------------------------------------------------------------
  45. //  Initialization and Free Methods
  46. //----------------------------------------------------------------------------------------------------
  47. - free
  48. {
  49.     if (image) [image free];
  50.     return [super free];
  51. }
  52.  
  53.  
  54. //----------------------------------------------------------------------------------------------------
  55. //  Accessing the Image
  56. //----------------------------------------------------------------------------------------------------
  57. - image
  58. {
  59.     return image;
  60. }
  61.  
  62. - image: anImage
  63. {
  64.     NXSize    imageSize;
  65.     NXRect    frameRect;
  66.     
  67.     if (image) [image free];
  68.     image = [anImage copy];
  69.     [image getSize: &imageSize];
  70.     NXSetRect (&frameRect, NX_X(&frame), NX_Y(&frame), imageSize.width, imageSize.height);
  71.     [self setFrame: &frameRect];
  72.     return self;
  73. }
  74.  
  75. //----------------------------------------------------------------------------------------------------
  76. //  Drawing
  77. //----------------------------------------------------------------------------------------------------
  78. - drawSelf: (const NXRect*) frameRect: (int) rects
  79. {
  80.     NXPoint    toPoint = { 0.0, 0.0 };
  81.     NXSetColor([[self window] backgroundColor]);
  82.     NXRectFill(&frame);
  83.     [image composite: NX_SOVER toPoint: &toPoint];
  84.     return self;
  85. }
  86.  
  87.  
  88. @end